package cn.k23.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

/**
 * @Description:
 * @Author: k23
 * @Date: 2022-04-01 22:52
 * @Version: 1.0
 */
@Configuration
public class UpFileConfig {
    @Bean
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver mu = new CommonsMultipartResolver();
        mu.setDefaultEncoding("utf-8");
        //一次请求最多是100MB
        mu.setMaxUploadSize(1024 * 1024 * 100);
        //一个请求一个文件最多是10MB
        mu.setMaxUploadSizePerFile(1024 * 1024 * 10);
        mu.setResolveLazily(true);
        //resolveLazily：延迟解析，默认为false--立即解析multipart request;
        //defaultEncoding：解析请求的默认字符编码 ; 默认值为"ISO-8859-1"。通常设置为"UTF-8";
        //maxUploadSize:文件上传最大值; 默认值为 -1(表示没有限制);
        //maxUploadSizePerFile:每个文件上传最大值;默认值为 -1(表示没有限制);
        //maxInMemorySize:存储在内存的最大值;默认值为10240B(10KB);
        //uploadTempDir:上传文件的临时目录;默认值为WEB应用程序的临时目录;
        return mu;
    }
}
